#include<bits/stdc++.h>
using namespace std;
struct node{
    int sum,i,x;
};node a[100005];
int b[100005];
int c[100005];
int main(){
    ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   freopen("detect.in","r",stdin);
   freopen("detect.out","w",stdout);
   int T;
   cin>>T;
   while(T--){
        memset(c,0,sizeof(c));
   int n,m,l,v,f=0;
   cin>>n>>m>>l>>v;
   for(int i=1; i<=n; i++){
    cin>>a[i].x>>a[i].sum>>a[i].i;
    if(a[i].i!=0){
        f=1;
    }
   }for(int i=1; i<=m; i++){
       cin>>b[i];
   }sort(b+1,b+1+m);
    if(f==0){
       int sum=0;
       for(int i=1; i<=n; i++){
         if(a[i].sum>v&&a[i].x<=b[m]){
            sum++;
         }
       }if(sum==0){
           cout<<sum<<" "<<m<<"\n";
       }else{
           cout<<sum<<" "<<m-1<<"\n";
       }
     }else{
         int sum=0;
         for(int i=1; i<=n; i++){
            if(a[i].i==0&&a[i].sum>v&&a[i].x<=b[m]){
                sum++;
            }else if(b[m]>=a[i].x&&sqrt(a[i].sum*a[i].sum+2*a[i].i*(b[m]-a[i].x))>v){
              sum++;
           }
         }if(sum==0){
            cout<<sum<<" "<<m<<"\n";
            continue;
         }cout<<sum<<" "<<m-1<<"\n";
      }
   }
   return 0;
}
